﻿using Common;
using Network.UpdateData;
using System.Net.Sockets;

namespace SFJDService.SocketHandle
{
    /// <summary>
    /// 管理员用户接收到消息后直接在XmlUsersData.xml里添加用户， 然后进行广播同步数据
    /// </summary>
    public class PH04AddUserAdmin : PacketHandle
    {
        public PH04AddUserAdmin(Socket socket, Packet packet) : base(socket, packet) { }

        /// <summary>
        /// message：name
        /// </summary>
        protected override void Handle()
        {
            if (Runtime.thisUser.IsAdmin)
            {
                ClassConfig config = new ClassConfig();
                ClassConfig temp = new ClassConfig();
                temp.DecodingFromString(Message);
                try
                {
                    config = Runtime.xmlUsers.GetUser(temp.UserName);
                }
                catch
                {
                    config.Copy(temp);
                    config.ToDefault();
                    config.UserName = temp.UserName;
                    Runtime.xmlUsers.AddUser(config);
                    Runtime.Printf("=====添加了新用户===== 【 " + config.UserName + " 】");
                    Delay(100);
                }
                Launcher.SendMsg2All(typeof(PH04AddUserOridary).GetDictianaryKey(), config.Coding2String());
            }
        }
    }
}
